package com.translate.controller;

import com.translate.commons.config.AsyncService;
import com.translate.service.service.task.DemoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 测一下线程
 * 好像是没导test就直接这么测了
 */
@RestController
@Slf4j
public class DemoController {

    @Autowired
    AsyncService asyncService;
    @Autowired
    DemoService demoService;

    /**
     * spring的异步线程
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public String create(@PathVariable("id") Long id) {
        log.info("*****开始*****");

        try {
            asyncService.doTaskThree(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("*****结束*****");
        return "1";
    }

    /**
     * 自定义的的异步线程
     * @param id
     * @return
     */
    @GetMapping("/get/{id}")
    public String create1(@PathVariable("id") String id) {
        log.info("*****开始*****");

        try {
            demoService.initData(id);
        } catch (Exception e) {
            e.printStackTrace();
        }
        log.info("*****结束*****");
        return "1";
    }

}
